﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：GroupInformationInfo
// 文件功能描述：班组管理
//
// 
// 创建标识：2012-08-06 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class GroupInformationInfo
    {
        /// <summary>
        /// 主键，班组groupId
        /// </summary>
        public int groupId
        {
            get;
            set;
        }
        /// <summary>
        /// 班组名称
        /// </summary>
        public string groupName
        {
            get;
            set;
        }
        /// <summary>
        /// 所属部门编号
        /// </summary>
        public string departmentId
        {
            get;
            set;
        }
        /// <summary>
        /// 所属部门名称
        /// </summary>
        public string departname
        {
            get;
            set;
        }

        private DataAccessGroupInformation dar;

        public GroupInformationInfo()
        {
            dar = new DataAccessGroupInformation();
        }
        /// <summary>
        /// 获取部门列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetdeptName()
        {
            return dar.GetdeptName();
        }

        /// <summary>
        /// 获取班组信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<GroupInformationInfo> SelGroupInfo(int pagesize, int startindex, string strquery, out int count)
        {
            IList<GroupInformationInfo> grolist = new List<GroupInformationInfo>();
            GroupInformationInfo groinfo;
            DataSet ds = dar.SelGroupInfo(pagesize, startindex, strquery, out count);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                groinfo = new GroupInformationInfo()
                {
                    groupId = Convert.ToInt32(item["groupId"]),
                    groupName = item["groupName"].ToString(),
                    departname = item["deptName"].ToString()
                };
                grolist.Add(groinfo);
            }
            return grolist;
        }

        /// <summary>
        /// 保存班组(新增界面下)
        /// </summary>
        /// <param name="rolepara"></param>
        /// <returns></returns>
        public int SaveGroupInformation(GroupInformationInfo gro)
        {
            object[] gropara = new object[] { gro.groupName, gro.departmentId };
            return dar.SaveGroupInformation(gropara);
        }

        /// <summary>
        /// 根据编号获取一条班组信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public GroupInformationInfo GetGroupInformationInfoOne(string id)
        {
            dar = new DataAccessGroupInformation();
            DataSet ds = dar.GetGroupInformationInfoOne(id);
            GroupInformationInfo info = new GroupInformationInfo();
            info.groupId = int.Parse(ds.Tables[0].Rows[0]["groupId"].ToString());
            info.groupName = ds.Tables[0].Rows[0]["groupName"].ToString();
            info.departmentId = ds.Tables[0].Rows[0]["departmentId"].ToString();
            return info;
        }

        /// <summary>
        /// 保存班组(修改界面下)
        /// </summary>
        /// <param name="rolepara"></param>
        /// <returns></returns>
        public int SaveGroupInformationEdit(GroupInformationInfo gro)
        {
            object[] gropara = new object[] { gro.groupId, gro.groupName, gro.departmentId};
            return dar.SaveGroupInformationEdit(gropara);
        }

        /// <summary>
        /// 删除班组
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int DeleteGroupInformation(string id)
        {
            return dar.DeleteGroupInformation(id);
        }
    }
}
